﻿/*
*author:徐洪昌
*blog:http://cnblogs.com/xusir
*datetime:${Utils.GetDate} ${Utils.GetTime}
*/ 
/*添加或修改数据*/
var ActionUrl =adminUrl+"${table.TableNameAlias}/";
var editId = 0;
jQuery(function () {
    editId = GetRequest()["id"];
    initPage();
	if (editId > 0) {
        loadData();
    }
});
/**
 *保存修改的数据
 */
function saveOrUpdate() {
    var param = jQuery("#form1").serialize();
    var methodName = editId > 0 ? "Edit" : "Add";
    commonBO.saveOrUpdate(methodName,param);
}

#foreach($c in $ColumnList)
	#if($c.IsPrimary)
	#set ($primaryKey=$c.ColumnNameAlias)
	#end
#end
/*初始化页面数据*/
function loadData() {
 var param={"${primaryKey}":editId};
jQuery.ajax({
	url: ActionUrl+"View"+admExtension,
	data: param,
	type:"post",
	dataType: "json",
        success: function (result) {
            if (result.status == "SUCCESS") {
#foreach($c in $ColumnList)
#if($c.IsPrimary)
jQuery("#hd${c.ColumnNameAlias}").val(result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#elseif($c.ColumnType=="Integer")
#if($c.ColumnName=="Status")
SetRadioChecked("Status",result.data.status);
#else
jQuery("#txt${c.ColumnNameAlias}").numberspinner("setValue",result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#end
#elseif($c.ColumnType=="Date")
 #if($c.ColumnName!="Update_Date"&&$c.ColumnName!="Create_Date")
jQuery("#txt${c.ColumnNameAlias}").datetimebox("setValue",result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
 #end
#else
jQuery("#txt${c.ColumnNameAlias}").val(result.data.${Utils.ToTitleLower($c.ColumnNameAlias)});
#end
#end
	}
	else
	{
		 commonBO.alertError(result);
	}
   },
    error: function () {
    jQuery.messager.alert('操作提醒', "操作失败，请查看错误日志或联系管理员！", 'error');
    }
	});
 }

 /*返回列表页*/
 function  backToList()
 {
     location.href="list.jsp";
 }
 /*初始化页面*/
function initPage() {
    commonBO.getEnumDictionary("StatusSpan", "radio", "SwitchStatus", "Status",	0);
}